2020-2021 Sunseeker Telemetry and Lighting System
timer_d_ex4_pwmUpDownMode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //*******************************************************************************
33 // MSP430F51x2 Demo - TimerD0, PWM TD0.1-2, Up/Down Mode, DCO SMCLK
34 //
35 // Description: This program generates two PWM outputs on P1.7 and P2.0 using
36 // TimerD0 configured for up/down mode. The value in CCR0, 128, defines the
37 // PWM period/2 and the values in CCR1 and CCR2 the PWM duty cycles. Using
38 // ~1.045MHz SMCLK as TDCLK, the timer period is ~233us with a 75% duty cycle
39 // on P1.7 and 25% on P2.0. PWM freq = 4kHz.
40 // SMCLK = MCLK = TDCLK = default DCO ~1.045MHz.
41 //
42 // MSP430F51x2
43 // -------------------
44 // /|\| |
45 // | | |
46 // --|RST |
47 // | |
48 // | P1.7/TD0.1|--> CCR1 - 75% PWM
49 // | P2.0/TD0.2|--> CCR2 - 25% PWM
50 //
51 //******************************************************************************
52 #include "driverlib.h"
53 
54 void main(void)
55 {
56  WDT_A_hold(WDT_A_BASE);
57  // configure ports
58  GPIO_setAsPeripheralModuleFunctionOutputPin(
59  GPIO_PORT_P1,
60  GPIO_PIN7
61  );
62 
63  GPIO_setAsPeripheralModuleFunctionOutputPin(
64  GPIO_PORT_P2,
65  GPIO_PIN0
66  );
67 
68  Timer_D_initCompareModeParam initComp1Param = {0};
69  initComp1Param.compareRegister = TIMER_D_CAPTURECOMPARE_REGISTER_1;
70  initComp1Param.compareInterruptEnable = TIMER_D_CAPTURECOMPARE_INTERRUPT_DISABLE;
71  initComp1Param.compareOutputMode = TIMER_D_OUTPUTMODE_TOGGLE_SET;
72  initComp1Param.compareValue = 32;
73  Timer_D_initCompareMode(TIMER_D0_BASE, &initComp1Param);
74 
75  Timer_D_initCompareModeParam initComp2Param = {0};
76  initComp2Param.compareRegister = TIMER_D_CAPTURECOMPARE_REGISTER_2;
77  initComp2Param.compareInterruptEnable = TIMER_D_CAPTURECOMPARE_INTERRUPT_DISABLE;
78  initComp2Param.compareOutputMode = TIMER_D_OUTPUTMODE_TOGGLE_SET;
79  initComp2Param.compareValue = 96;
80  Timer_D_initCompareMode(TIMER_D0_BASE, &initComp2Param);
81 
82  Timer_D_initUpDownModeParam initUpDownParam = {0};
83  initUpDownParam.clockSource = TIMER_D_CLOCKSOURCE_SMCLK;
84  initUpDownParam.clockSourceDivider = TIMER_D_CLOCKSOURCE_DIVIDER_1;
85  initUpDownParam.clockingMode = TIMER_D_CLOCKINGMODE_EXTERNAL_CLOCK;
86  initUpDownParam.timerPeriod = 128;
87  initUpDownParam.timerInterruptEnable_TDIE = TIMER_D_TDIE_INTERRUPT_DISABLE;
88  initUpDownParam.captureCompareInterruptEnable_CCR0_CCIE =
89  TIMER_D_CAPTURECOMPARE_INTERRUPT_DISABLE;
90  initUpDownParam.timerClear = TIMER_D_DO_CLEAR;
91  Timer_D_initUpDownMode(TIMER_D0_BASE, &initUpDownParam);
92 
93  Timer_D_startCounter(
94  TIMER_D0_BASE,
95  TIMER_D_UP_MODE
96  );
97 
98  __bis_SR_register(LPM0_bits); // Enter LPM0
99  __no_operation(); // For debugger
100 }
101 
__no_operation()
void main(void)